package com.hlddz.venue_reservation.controller;


import com.hlddz.venue_reservation.entity.User;
import com.hlddz.venue_reservation.entity.Visitor;
import com.hlddz.venue_reservation.service.VisitorService;
import com.hlddz.venue_reservation.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author MoShang
 * @since 2024年05月31日
 */
@RestController
@RequestMapping("/visitor")
public class VisitorController {
    @Autowired
    private VisitorService visitorService;
    @PostMapping(value = "/addVisitor")
    public Result addVisitor(@RequestBody Visitor visitor){
        try {
            visitorService.addVisitor(visitor);
            return Result.success("添加成功");
        }catch (Exception e){
            return Result.error("500","添加失败");
        }
    }

    @PostMapping(value = "/delVisitor")
    public Result delVisitor(@RequestParam("username") String username){
        try {
           visitorService.delVisitor(username);
            return Result.success("删除成功");
        } catch (Exception e) {
            return Result.error("500","删除失败");
        }
    }
    @GetMapping(value = "/getVisitorInfo")
    public Result getVisitorInfo(@RequestParam("username") String username) {
        try {
            System.out.println("1111");
            List<Visitor> visitors = visitorService.getVisitorInfo(username);
            return Result.success(visitors, "获取成功");
        } catch (Exception e) {
            return Result.error("500", "获取失败");
        }
    }


}

